An excursion set model for the distribution of dark matter and dark matter haloes