You have to book it about a month in advance.

If you're planning on lots of rail travel maybe look at the Eurail pass.