Application of Legendre series to the optimal control of integrodifferential equations