You used to be able to buy a Tarjeta Dorada as an e-ticket for €10 from the Renfe office in London, so you could make bookings in advance - but that facility closed.
So you have to buy it from a Renfe booking office on arrival in Spain, and trust there is spare capacity on the trains you want.
Also the discounts do not apply to what we would call "Advance" tickets - only to the regular fares.
Nevertheless, 40% off the ordinary fares, for a flexible ticket, is a good deal.
The TD lasts a year, so you might be able to use it on more than one trip.