I've needed to do something with selecting trays as well, but could never get it done completely in PostScript, so I cheated and used PJL at the head of my PostScript code:
{Esc]%-12345X@PJL
@PJL SET MEDIASOURCE = TRAY1
@PJL ENTER LANGUAGE = POSTSCRIPT
[Ctrl-D]%!
%!PS-Adobe
% All My PostSCript Code
It worked for my circumstances, but I have only tested this to an HP4050 printer. I found this code by examining the postscript ppd file for this printer on my SuSE 9.2 system.