On the second boundary value problem for Monge-Ampère type equations and optimal transportation