Optimal shepherding and transport of a flock