Connecting all three together

2 x dual VNH5019 MOTOR DRIVER SHIELD

4 x Geared motor w/encoder(https://www.littlebirdelectronics.com.au/metal-dc-geared-motor-w-encoder-12v-251rpm-18kg.cm)

arduino mega 2560

Im having some trouble I know how you would connect the encoder straight to the arduino but dont understant how u do it through the motor driver. I need to create a robot that will go through a maze so i need to be accurate with distances

Encoders are not normally connected via the motor driver. Motor driver drives the motor. Encoder produces a signal for the Arduino. Connect the wires of your motor accordingly.