Differentiate, set to zero, solve.
This, but the function to use is not the one shown. You need to get D in terms of theta (the angle).
I can't help with this for shit, but I am curious about something. There is no other information provided. Wouldn't things like the cannon ball size and weight factor into the range? Or is that covered in that formula I don't understand?
This branch of dynamics, kinematics, does not deal with mass and forces, only with displacements, velocities and accelerations. Kinetics would start to deal with things like mass, energy and momentum.
Also, couldn't this equation just be plugged into a graphing calculator and graphed? Just find the maximum height of the curve along y-axis and that should be your maximum range. No?
Yes, but the analytic way to do what you've described is what rumborak said.