According to a neuroscience PhD student's widely reported blog post:
“If we are drinking caffeine at a time when your cortisol concentration in the blood is at its peak, you probably should not be drinking it. This is because cortisol production is strongly related to your level of alertness and cortisol peaks for your 24 hour rhythm between 8 and 9am on average. One of the key principles of pharmacology is use a drug when it is needed. Otherwise, we can develop tolerance to a drug administered at the same dose. In other words, the same cup of morning coffee will become less effective and this is probably why I need a shot of espresso in mine now. In the morning then, your coffee will probably be the most effective if you enjoy it between 9.30am and 11.30am, when your cortisol levels are dropping before the next spike."
As for when to drink in terms of the stage of your work I'm sure, as you suggest, this would vary depending on personal habits and work styles. I think making a quick coffee would be a good Pomodoro-break activity (standing up and doing something practical and non-cerebral after a spell of thinking helps me prepare my brain for more work!).
So maybe combine the above research with how long you find coffee takes to have its maximum effect on you personally (probably between 30-60 minutes), and when you want to feel at peak strength ;-)