Finding optimal time since event to administer treatment

Suppose an event happens to a subject, a treatment is administered t hours later, and then some binary outcome is recorded (outcome=1 (desired outcome) or outcome=0). From past data, we would like to be able to find the value of t that maximizes the probability of outcome=1 for some future subject, given everything we know about them. So a given row of data might look like:

[d1, d2, d3, …, dn, t, y] where d1,d2…dn are things we know about the subject, t is the time from event to treatment, and y is the binary outcome variable. What is the best way of solving this optimization problem?

One thought is to model P(y=1 | t, d) using logistic regression and then, when presented with a new subject, plug in their values of d and several different values of t, choosing the t that maximizes the probability. But this feels inelegant and indirect. Is there a better way of thinking about this type of problem, preferably one where t could be predicted directly?