You can take the test any time in the 3 days before the service on which you will arrive in England departs.
For example, if you travel directly to England on Friday, you could take a test any time on the Tuesday, Wednesday, Thursday or Friday. The test result must be available for boarding.
Everyone entering England from overseas (including UK nationals and residents) must provide proof of a negative COVID-19 test taken within 3 days of departure to England.