Dynamical maximum entropy approach to flocking