Statistical mechanics of a system of interacting dislocations: a self-consistent field approach