Shortcut to adiabaticity in a Stern-Gerlach apparatus