You can cancel a Direct Debit through your bank whenever you like — but it's usually simpler to leave it in place until the final bill has been settled.
Cancelling doesn't settle the bill or close the account. If you cancel before the final bill is collected, you'll need to arrange payment another way and tell the provider you've done it — otherwise the balance sits there unpaid, which is how people end up in arrears with a company they've already left.
It can also slow a refund down, because credit is often returned to the account the payments came from. If you've already cancelled, give the provider the bank details you want the money sent to.