An ensemble of spherical particles with arbitrary dielectric permittivity and magnetic permeability was considered in the dipole approximation. Each particle was described by complex electric and magnetic polarizabilities. A computational approach based on the coupled dipole method, also called the discrete dipole approximation, was used to derive the optical force experienced by each particle due to an incident electromagnetic field and the fields scattered by all other particles. This approach is general and can handle material dispersion and losses. In order to illustrate this approach, we studied the case of two spherical particles separated by a distance d, and illuminated by an incident plane wave whose wave vector is normal to the axis of the particles. We computed the optical force experienced by each particle in the direction of the beam (radiation pressure), and perpendicular to the beam (optical binding) for particles with positive and negative refractive indices. We also considered the effect of material losses.