From a posteriori to a priori solutions for a two-level system interacting with a single-photon wavepacket