You can apply for a letter whenever you want because this letter is valid from the date of entry you enter, not from the date you applied for it or from the date that you got your issued letter.
At the latest, you should apply for this letter before 4-7 working days to avoid having to pay additional urgent visa processing fees as well as to have time to recheck the information.